package org.easyupdater.model;

import java.io.File;

import org.osgi.framework.Version;

import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("bundle")
public class BundleSpec {
	private String id;
	private String version;
	private String url;
	
	private transient File localJar;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((version == null) ? 0 : version.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BundleSpec other = (BundleSpec) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (version == null) {
			if (other.version != null)
				return false;
		} else if (!new Version(version).equals(new Version(other.version)))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return id + "-" + version;
	}

	public File getLocalJar() {
		return localJar;
	}

	public void setLocalJar(File localJar) {
		this.localJar = localJar;
	}
}
